package com.changeover.gwt.client.view.impl;

import com.changeover.gwt.client.view.ICustomerDetails;
import com.changeover.gwt.shared.model.customer.ICustomer;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.CaptionPanel;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.LayoutPanel;
import com.google.gwt.user.client.ui.TabPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class CustomerDetailsView extends Composite implements ICustomerDetails {

    //private ICustomer customer;
//    private Grid customerDataGrid;
//    private ListBox statusCombo;
//    private DateBox remainderDateBox;
    private Button closeButton;

    public CustomerDetailsView(ICustomer customer) {
        VerticalPanel verticalPanel = new VerticalPanel();
        initWidget(verticalPanel);
        verticalPanel.setHeight("695px");
        if (customer == null) {
            Label label = new Label("No customer was chosen. Please go to \"WorkList\" tab and click on customer.");
            verticalPanel.add(label);
            return;
        }
//        verticalPanel.setSize("680px", "269px");
        
        closeButton = new Button("Close");
        closeButton.setText("Abandon");
        closeButton.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                ((DialogBox)getParent().getParent()).hide();
            }
        });
        
        LayoutPanel customerDataPanel = new LayoutPanel();
        customerDataPanel.setSize("860px", "40px");
        
        Label lblNewLabel_1 = new Label("Customer-ID: " + customer.getId());
        customerDataPanel.add(lblNewLabel_1);
        customerDataPanel.setWidgetLeftWidth(lblNewLabel_1, 0.0, Unit.PX, 200, Unit.PX);
        customerDataPanel.setWidgetTopHeight(lblNewLabel_1, 0.0, Unit.PX, 18.0, Unit.PX);
        
        Label lblNewLabel_2 = new Label("Customer Type: C (Company)");
        customerDataPanel.add(lblNewLabel_2);
        customerDataPanel.setWidgetLeftWidth(lblNewLabel_2, 220, Unit.PX, 200, Unit.PX);
        customerDataPanel.setWidgetTopHeight(lblNewLabel_2, 0.0, Unit.PX, 18.0, Unit.PX);
        
        Label lblNewLabel_3 = new Label("Branch: 001");
        customerDataPanel.add(lblNewLabel_3);
        customerDataPanel.setWidgetLeftWidth(lblNewLabel_3, 440, Unit.PX, 200, Unit.PX);
        customerDataPanel.setWidgetTopHeight(lblNewLabel_3, 0.0, Unit.PX, 18.0, Unit.PX);
        
        Label lblNewLabel_4 = new Label("Name: " + customer.getName());
        customerDataPanel.add(lblNewLabel_4);
        customerDataPanel.setWidgetLeftWidth(lblNewLabel_4, 0, Unit.PX, 200, Unit.PX);
        customerDataPanel.setWidgetTopHeight(lblNewLabel_4, 22, Unit.PX, 18.0, Unit.PX);
        
        CaptionPanel captionPanel = new CaptionPanel(" Customer ");
        captionPanel.setStyleName("caption-panel");
        captionPanel.setContentWidget(customerDataPanel);
        verticalPanel.add(captionPanel);

        LayoutPanel splitPanel = new LayoutPanel();
        splitPanel.setSize("100%", "20px");
        verticalPanel.add(splitPanel);
        
        TabPanel tabPanel = new TabPanel();
        tabPanel.setHeight("610px");
        verticalPanel.add(tabPanel);
        
        CustomerMainDataTab tab1 = new CustomerMainDataTab();
        tabPanel.add(tab1, "Main Data");
        
//        customerDataGrid = new Grid(2, 7);
//        customerDataWrapper.add(customerDataGrid);
//        customerDataGrid.setWidth("674px");
//        customerDataGrid.getRowFormatter().getElement(0).getStyle().setBackgroundColor("#BBBBBB");
//        
//        customerDataGrid.setStyleName((String) null);
//        customerDataGrid.setBorderWidth(1);
//        customerDataGrid.setText(0, 0, "ID");
//        customerDataGrid.setText(0, 1, "Name");
//        customerDataGrid.setText(0, 2, "Address");
//        customerDataGrid.setText(0, 3, "ZIP");
//        customerDataGrid.setText(0, 4, "City");
//        customerDataGrid.setText(0, 5, "Telephone");
//        customerDataGrid.setText(0, 6, "Mobile");
//        
//        LayoutPanel layoutPanel = new LayoutPanel();
//        customerAccountPanel.add(layoutPanel);
//        layoutPanel.setSize("", "84px");
//        
//        Label lblCompanyMembers = new Label("Company members");
//        layoutPanel.add(lblCompanyMembers);
//        layoutPanel.setWidgetLeftWidth(lblCompanyMembers, 0.0, Unit.PX, 130.0, Unit.PX);
//        layoutPanel.setWidgetTopHeight(lblCompanyMembers, 0.0, Unit.PX, 18.0, Unit.PX);
//        
//        Grid companyMembersGrid = new Grid(2, 2);
//        companyMembersGrid.setBorderWidth(1);
//        layoutPanel.add(companyMembersGrid);
//        layoutPanel.setWidgetRightWidth(companyMembersGrid, 525.0, Unit.PX, 150.0, Unit.PX);
//        companyMembersGrid.setSize("150px", "50px");
//        layoutPanel.setWidgetTopHeight(companyMembersGrid, 24.0, Unit.PX, 100.0, Unit.PX);
//        companyMembersGrid.getRowFormatter().getElement(0).getStyle().setBackgroundColor("#BBBBBB");
//        companyMembersGrid.setText(0, 0, "ID");
//        companyMembersGrid.setText(0, 1, "Name");
//        
//        Grid ownAccountsGrid = new Grid(2, 3);
//        ownAccountsGrid.setBorderWidth(1);
//        layoutPanel.add(ownAccountsGrid);
//        layoutPanel.setWidgetLeftWidth(ownAccountsGrid, 185.0, Unit.PX, 230.0, Unit.PX);
//        layoutPanel.setWidgetTopHeight(ownAccountsGrid, 24.0, Unit.PX, 52.0, Unit.PX);
//        ownAccountsGrid.setWidth("230px");
//        ownAccountsGrid.getRowFormatter().getElement(0).getStyle().setBackgroundColor("#BBBBBB");
//        ownAccountsGrid.setText(0, 0, "ID");
//        ownAccountsGrid.setText(0, 1, "Type");
//        ownAccountsGrid.setText(0, 2, "Authorized");
//        
//        Grid authorizedForGrid = new Grid(2, 3);
//        authorizedForGrid.setBorderWidth(1);
//        layoutPanel.add(authorizedForGrid);
//        layoutPanel.setWidgetLeftWidth(authorizedForGrid, 445.0, Unit.PX, 230.0, Unit.PX);
//        authorizedForGrid.setWidth("230px");
//        layoutPanel.setWidgetTopHeight(authorizedForGrid, 24.0, Unit.PX, 100.0, Unit.PX);
//        authorizedForGrid.getRowFormatter().getElement(0).getStyle().setBackgroundColor("#BBBBBB");
//        authorizedForGrid.setText(0, 0, "ID");
//        authorizedForGrid.setText(0, 1, "Type");
//        authorizedForGrid.setText(0, 2, "Owner");
//        
//        Label lblNewLabel = new Label("Own accounts");
//        layoutPanel.add(lblNewLabel);
//        layoutPanel.setWidgetLeftWidth(lblNewLabel, 185.0, Unit.PX, 150.0, Unit.PX);
//        layoutPanel.setWidgetTopHeight(lblNewLabel, 0.0, Unit.PX, 18.0, Unit.PX);
//        
//        Label lblAuthorizedFor = new Label("Authorized for");
//        layoutPanel.add(lblAuthorizedFor);
//        layoutPanel.setWidgetLeftWidth(lblAuthorizedFor, 445.0, Unit.PX, 100.0, Unit.PX);
//        layoutPanel.setWidgetTopHeight(lblAuthorizedFor, 0.0, Unit.PX, 18.0, Unit.PX);
        
        Label relationLabel = new Label("Here will be Customer Relations");
        tabPanel.add(relationLabel, "Relations");
        
        Label accountLabel = new Label("Here will be Customer Accounts");
        tabPanel.add(accountLabel, "Accounts");
        
        Label onlineLabel = new Label("Here will be Customer Online");
        tabPanel.add(onlineLabel, "Online");
        
        CustomerStatusTab tab2 = new CustomerStatusTab();
        tabPanel.add(tab2, "Status");
        
//        VerticalPanel statusPanel = new VerticalPanel();
//        tabPanel.add(statusPanel, "Status");
//        statusPanel.setSize("680px", "189px");
        
        Label cloudLabel = new Label("Here will be Customer Cloud");
        tabPanel.add(cloudLabel, "Cloud");
//        
//        CaptionPanel actionWrapper = new CaptionPanel("Action");
//        statusPanel.add(actionWrapper);
//        actionWrapper.setWidth("700px");
//        
//        LayoutPanel actionLayoutPanel = new LayoutPanel();
//        actionWrapper.setContentWidget(actionLayoutPanel);
//        actionLayoutPanel.setSize("697px", "126px");
        
//        Label lblStatus = new Label("Status");
//        actionLayoutPanel.add(lblStatus);
//        actionLayoutPanel.setWidgetLeftWidth(lblStatus, 0.0, Unit.PX, 65.0, Unit.PX);
//        actionLayoutPanel.setWidgetTopHeight(lblStatus, 10.0, Unit.PX, 18.0, Unit.PX);
//        
//        statusCombo = new ListBox();
//        statusCombo.addItem("correspondence started", "1");
//        statusCombo.addItem("not responding", "2");
//        actionLayoutPanel.add(statusCombo);
//        actionLayoutPanel.setWidgetLeftWidth(statusCombo, 71.0, Unit.PX, 129.0, Unit.PX);
//        actionLayoutPanel.setWidgetTopHeight(statusCombo, 10.0, Unit.PX, 22.0, Unit.PX);
//        
//        Label lblSetReminder = new Label("Set reminder");
//        actionLayoutPanel.add(lblSetReminder);
//        actionLayoutPanel.setWidgetLeftWidth(lblSetReminder, 224.0, Unit.PX, 91.0, Unit.PX);
//        actionLayoutPanel.setWidgetTopHeight(lblSetReminder, 10.0, Unit.PX, 18.0, Unit.PX);
//        
//        remainderDateBox = new DateBox();
//        
////        DateTimeFormat.getFormat("dd/mm/yyyy")
//        remainderDateBox.setFormat(new DateBox.DefaultFormat(DateTimeFormat.getFormat("dd/MM/yyyy")));
//        //remainderDateBox.setFormat(DateFormat.);
//        actionLayoutPanel.add(remainderDateBox);
//        actionLayoutPanel.setWidgetLeftWidth(remainderDateBox, 321.0, Unit.PX, 129.0, Unit.PX);
//        actionLayoutPanel.setWidgetTopHeight(remainderDateBox, 10.0, Unit.PX, 23.0, Unit.PX);
//        
//        Label lblComment = new Label("Comment");
//        actionLayoutPanel.add(lblComment);
//        actionLayoutPanel.setWidgetLeftWidth(lblComment, 0.0, Unit.PX, 65.0, Unit.PX);
//        actionLayoutPanel.setWidgetTopHeight(lblComment, 45.0, Unit.PX, 22.0, Unit.PX);
//        
//        TextArea commentTextArea = new TextArea();
//        actionLayoutPanel.add(commentTextArea);
//        actionLayoutPanel.setWidgetLeftWidth(commentTextArea, 71.0, Unit.PX, 379.0, Unit.PX);
//        actionLayoutPanel.setWidgetTopHeight(commentTextArea, 45.0, Unit.PX, 53.0, Unit.PX);
//        
//        Button actionSaveButton = new Button("Save");
//        actionLayoutPanel.add(actionSaveButton);
//        actionLayoutPanel.setWidgetLeftWidth(actionSaveButton, 400.0, Unit.PX, 82.0, Unit.PX);
//        actionLayoutPanel.setWidgetTopHeight(actionSaveButton, 104.0, Unit.PX, 22.0, Unit.PX);
//        
//        CaptionPanel historyWrapper = new CaptionPanel("History");
//        statusPanel.add(historyWrapper);
//        historyWrapper.setSize("702px", "205px");
//        
        tabPanel.selectTab(0);
        
        
        
        
        
//        verticalPanel.add(closeButton);
//        verticalPanel.setCellHorizontalAlignment(closeButton, HasHorizontalAlignment.ALIGN_RIGHT);
//        closeButton.setWidth("75px");
        
        // Set data
//        customerDataGrid.setText(1, 0, customer.getId().toString());
//        customerDataGrid.setText(1, 1, customer.getName());
//        statusCombo.setItemSelected(customer.getLastAction().getId() - 1, true);
//        remainderDateBox.setValue(customer.getRemainder());
    }
    
    public Widget asWidget() {
        return this;
    }
    
    public Button getCloseButton() {
        return closeButton;
    }
}
